package xslt_test;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Source;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import java.io.File;

/**
 * @author Eugen, 6/19/12 12:51 AM
 */
public class Transformer {
    /*public static void main(String[] args) throws Exception {
*//*        System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
             "net.sf.saxon.dom.DocumentBuilderFactoryImpl");*//*
        System.setProperty("javax.xml.transform.TransformerFactory",
                "net.sf.saxon.TransformerFactoryImpl");

        File xmlFile = new File("WineOrderingBPEL/src/test/java/xslt_test/test.xml");
        File xsltFile = new File("WineOrderingBPEL/src/test/java/xslt_test/test.xslt");
        File xmlFile2 = new File("WineOrderingBPEL/src/test/java/xslt_test/test2.xml");

        // JAXP reads data using the Source interface
        Source xmlSource = new StreamSource(xmlFile);
        Source xsltSource = new StreamSource(xsltFile);
        Source xml2Source = new StreamSource(xmlFile2);

        // the factory pattern supports different XSLT processors
        TransformerFactory transFact =
                TransformerFactory.newInstance();
        javax.xml.transform.Transformer trans = transFact.newTransformer(xsltSource);
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        dbFactory.setNamespaceAware(true);
		DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
		Document doc = dBuilder.parse(xmlFile2);
		doc.getDocumentElement().normalize();
        Node warehouses = doc.getDocumentElement();
        System.out.println("name="+warehouses.getNodeName());

        trans.setParameter("Warehouses",warehouses);
        trans.transform(xmlSource, new StreamResult(System.out));
    }*/

    public static void main(String[] args) throws Exception {
        System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
                "net.sf.saxon.dom.DocumentBuilderFactoryImpl");
        System.setProperty("javax.xml.transform.TransformerFactory",
                "net.sf.saxon.TransformerFactoryImpl");

        File xmlFile = new File("WineOrderingBPEL/src/test/java/xslt_test/test.xml");
        File xsltFile = new File("WineOrderingBPEL/src/test/java/xslt_test/test.xslt");

        // JAXP reads data using the Source interface
        Source xmlSource = new StreamSource(xmlFile);
        Source xsltSource = new StreamSource(xsltFile);

        // the factory pattern supports different XSLT processors
        TransformerFactory transFact =
                TransformerFactory.newInstance();
        javax.xml.transform.Transformer trans = transFact.newTransformer(xsltSource);
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        dbFactory.setNamespaceAware(true);
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        trans.transform(xmlSource, new StreamResult(System.out));
    }
}
